<template>
  <el-card class="mt">
    <template #header>
      <el-button>添加用户</el-button>
      <el-button type="primary">编辑用户</el-button>
      <el-button type="success">删除用户</el-button>
    </template>
    <el-table :data="userList">
      <el-table-column type="selection" width="60" align="center" />
      <el-table-column prop="username" label="账号" align="center" />
      <el-table-column prop="email" label="邮箱" align="center" />
      <el-table-column prop="avatar" label="头像" align="center" />
      <el-table-column prop="status" label="状态" align="center">
        <template #default="scope">
          <el-tag :type="scope.row.status ? 'primary' : 'danger'">{{ scope.row.status ? '启用' : '禁用' }}</el-tag>
          <span></span>
        </template>
      </el-table-column>
      <el-table-column prop="created_time" label="创建时间" align="center" />
      <el-table-column fixed="right" label="操作" min-width="90" align="center">
        <template #default="scope">
          <el-button link type="warning" icon="Edit" @click="onEidt(scope.row.id)">编辑</el-button>
          <el-button link type="danger" icon="Delete" @click="onRemove(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <template #footer>
      <div class="flex flex-justify-end">
        <el-pagination background layout="total, sizes, prev, pager, next, jumper"
          v-model:current-page="paginationParams.page_index" v-model:page-size="paginationParams.page_size"
          :page-sizes="[10, 20, 30, 40]" :total="userTotal" @size-change="loadTableData"
          @current-change="loadTableData" />
      </div>
    </template>
  </el-card>
</template>

<script lang="ts" setup>
import { storeToRefs } from "pinia"
import useSystemStore from "@/store/system"
import { reactive, ref } from "vue"
import type { PaginationForm } from "@/types"

const systemStore = useSystemStore()
const { userList, userTotal } = storeToRefs(systemStore)
// 分页
var paginationParams = reactive<PaginationForm>({
  page_index: 1,
  page_size: 10
})

loadTableData();

/**
 * 列表查询
 * @param searchParams pageSearch form传过来的查询条件
 */
function loadTableData(searchParams: any = {}) {
  systemStore.loadUserList({ ...paginationParams, ...searchParams })
}

/**
 * 删除数据
 * @param id
 */
function onRemove(id: number) { }

/**
 * 编辑数据
 * @param id
 */
function onEidt(id: number) { }

defineExpose({ loadTableData })
</script>

<style lang="scss" scoped></style>
